﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text.RegularExpressions;


namespace carsitem.yuangong
{
    public partial class tianjia : Form
    {
        Sunisoft.IrisSkin.SkinEngine se = null;
        string skinname = "SteelBlack";
        public tianjia()
        {
            InitializeComponent();
            //加载皮肤
            se = new Sunisoft.IrisSkin.SkinEngine();
            se.SkinAllForm = true;
            se.SkinFile = "skin/" + skinname + ".ssk";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }//退出功能

        private void button1_Click(object sender, EventArgs e)
        {
            //创建连接对象
            SqlConnection conn = new SqlConnection("Data Source=季白\\MSSQLSERVER04;Initial Catalog=SellCars;Integrated Security=True");
            //打开连接
            conn.Open();
            int st =0;
            //接收用户输入的数据
            if (this.xingming.Text=="")
            {
                MessageBox.Show("员工姓名不能为空");
                return;
            }
            string name = this.xingming.Text;//姓名
            if (this.bumeng.Text=="")
            {
                MessageBox.Show("部门不能为空");
                return;
            }
            string bumeng = this.bumeng.Text;//部门
                string bm1 = string.Format(@"select DepartID from Department where DepartName='{0}'",bumeng);
                DBHelper dh = new DBHelper();
                st =Convert.ToInt32( dh.GetDataTableBySql(bm1).Rows[0]["DepartID"].ToString());
            if (this.gongzi.Text == "")
            {
                MessageBox.Show("工资不能为空");
                return;
            }
            string gongzi = this.gongzi.Text;//工资
            if (this.shouji.Text == "")
            {
                MessageBox.Show("手机不能为空");
                return;
            }
            string shouji = this.shouji.Text;//手机
            IsNumberic(shouji);
            if (this.shouji.Text.Length != 11)
            {
                MessageBox.Show("手机号码为11位！");
            }
            else
            {
                if ((this.radioButton1.Checked == false) && (this.radioButton2.Checked == false))
                {
                    MessageBox.Show("请选择性别");
                    return;
                }
                string xingb = "";//性别
                if (this.radioButton1.Checked == true)
                {
                    xingb = "男";
                }
                if (this.radioButton2.Checked == true)
                {
                    xingb = "女";
                }
                if (this.mima.Text == "")
                {
                    MessageBox.Show("密码不能为空");
                    return;
                }
                string mima = this.mima.Text;//密码
                string zhuzhi = this.zhuzhi.Text;//住址
                string zhiwei = this.zhiwei.Text;//职位


                string sql = string.Format("insert Employee values('{0}','{1}','{2}','{3}','{4}','{5}', '{6}', '{7}')", st, name, gongzi, xingb, shouji, mima, zhuzhi, zhiwei);
                SqlCommand com = new SqlCommand(sql, conn);
                //判断是否是有影响行数
                int count = com.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
            
        }//添加功能

        private void tianjia_FormClosed(object sender, FormClosedEventArgs e)
        {
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }
        public bool IsNumberic(string oText)
        {
            string pattern = @"^\d+(\.\d)?$";
            if (oText != "")
            {
                if (!Regex.IsMatch(oText, pattern))
                    MessageBox.Show("请输入数字！");
            }
            return true;
        }
    }
}
